﻿@inherits UmbracoTemplatePage<IPublishedContent>

@{ 
    string pathstring = ViewData["pathstring"] as string;
    string[] paths = pathstring.Split(',');
    int pathLength = paths.Length;

    //@(pathLength > 3 && level1.Id.ToString() == paths[3] ? "active open" : "")
}
<div class="sidebar-area col-md-3">
    <nav>
        <ul class="level-1">
            @{
                IEnumerable<IPublishedContent> childLevel1 = Model.Content.Children.Where(x => x.IsVisible());
                foreach (IPublishedContent level1 in childLevel1)
                {
                    <li class="@(pathLength > 3 && level1.Id.ToString() == paths[3] ? "active open" : "")">
                        <h3><a href="@level1.Url">@level1.Name</a></h3>
                        @if (level1.Children.Any(x => x.IsVisible() && !x.GetPropertyValue<bool>("hideInSidebar")))
                        {
                            IEnumerable<IPublishedContent> childLevel2 = level1.Children.Where(x => x.IsVisible());

                            <ul class="level-2">
                                @foreach (IPublishedContent level2 in childLevel2)
                                {
                                    <li class="@(pathLength > 4 && level2.Id.ToString() == paths[4] ? "active open" : "")">
                                        <h4><a href="@level2.Url">@level2.Name</a></h4>
                                        @if (level2.Children.Any(x => x.IsVisible() && !x.GetPropertyValue<bool>("hideInSidebar")))
                                        {
                                            IEnumerable<IPublishedContent> childLevel3 = level2.Children.Where(x => x.IsVisible());
                                            <ul class="level-3">
                                                @foreach (IPublishedContent level3 in childLevel3)
                                                {
                                                    <li class="@(pathLength > 5 && level3.Id.ToString() == paths[5] ? "active open" : "")"><h5><a href="@level3.Url">@level3.Name</a></h5></li>
                                                }

                                            </ul>
                                        }
                                    </li>
                                }
                            </ul>
                        }
                    </li>
                }
            }
        </ul>
    </nav>
</div>